import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-11-12
 * Time: 13:55
 */
public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> A = new ArrayList<>();
        List<Integer> B = new ArrayList<>();
        System.out.println("请输入整数集合A，输入#号代表结束");
        while (scanner.hasNextInt()) {
            A.add(scanner.nextInt());
        }
        scanner.nextLine();
        System.out.println("请输入整数集合B，输入#号代表结束");
        while (scanner.hasNextInt()) {
            B.add(scanner.nextInt());
        }
        union(A, B);
        System.out.println("A和B的并集：" + A);
    }

    public static void union(List<Integer> list1, List<Integer> list2) {
        for (int i = 0; i < list2.size(); i++) {
            if(list1.indexOf(list2.get(i)) == -1) {
                list1.add(list2.get(i));
            }
        }
    }
}
